
//
//  ViewController.m
//  friendlist
//
//  Created by Craig Hewitt on 8/22/13.
//  Copyright (c) 2013 SJM. All rights reserved.
//

#import "ViewController.h"
#import "GraphViewController.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.rangeList  = [[NSArray alloc] initWithObjects:@"6 Hours",@"12 Hours",@"24 Hours",@"5 Days",@"14 Days",@"31 Days",@"90 Days",@"180 Days",@" 1 Year", nil];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
}

// returns the # of rows in each component
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent: (NSInteger)component
{
    return [self.rangeList count];
}

-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    return [self.rangeList objectAtIndex:row];
    
}

-(void) saveRange: ( NSString *) range setInterval:(NSString *) interval
{
    
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    
    [defaults setObject:range forKey:@"Range"];
    [defaults setObject:interval forKey:@"Interval"];
    // Synchronizing the defaults. If you don't do this the defaults may or may not sync.
    [defaults synchronize];
}




- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
  

// description of the used values/intervals
//check https://xively.com/dev/docs/api/quick_reference/historical_data/
//    Interval 	Description                     Maximum range in One Query
//    0         Every datapoint stored          6 hours
//    30        One datapoint every 30 seconds	12 hours
//    60        One datapoint every minute      24 hours
//    300       One datapoint every 5 minutes	5 days
//    900       One datapoint every 15 minutes	14 days
//    1800      One datapoint per 30 minutes	31 days
//    3600      One datapoint per hour          31 days
//    10800     One datapoint per three hours	90 days
//    21600     One datapoint per six hours     180 days
//    43200     One datapoint per twelve hours	1 year
//    86400     One datapoint per day           1 year
    
  
      NSLog(@"Selected Range %d", row);
    switch(row)
    {
        case 0:
            self.pickerSelection.text = @"6 Hours";
            [self saveRange:@"6hours" setInterval:@"0"];
            break;
        case 1:
            self.pickerSelection.text = @"12 Hours";
             [self saveRange:@"12hours" setInterval:@"30"];
            break;
        case 2:
            self.pickerSelection.text = @"24 Hours";
             [self saveRange:@"24hours" setInterval:@"60"];
            break;
        case 3:
            self.pickerSelection.text = @"5 Days";
             [self saveRange:@"5days" setInterval:@"300"];
            break;
        case 4:
            self.pickerSelection.text = @"14 Days";
             [self saveRange:@"14days" setInterval:@"900"];
            break;
        case 5:
            self.pickerSelection.text = @"31 Days";
             [self saveRange:@"31days" setInterval:@"1800"];
            break;
        case 6:
            self.pickerSelection.text = @"90 Days";
             [self saveRange:@"90days" setInterval:@"10800"];
            break;
        case 7:
            self.pickerSelection.text = @"180 Days";
             [self saveRange:@"180days" setInterval:@"21600"];
            break;
        case 8:
            self.pickerSelection.text = @"1 Year";
             [self saveRange:@"1year" setInterval:@"43200"];
            break;
    }
}

-(void) setDataStreamIndex:(int)index
{
    
}
@end
